<template>
    <view>
        <form>
          <xmInfo
      :projectno="dataInfo.projectno"
      :projectname="dataInfo.name"
    ></xmInfo>
           <view class="cu-card">
                <view class="cu-form-group">
                    <view class="title">整改期限</view>
                    <view>{{ dataInfo.endtime  || '' }}</view>
                    <!-- <picker mode="date" :value="dataInfo.endtime"  @change="DateChange('endtime',$event)" :disable="true">
                        <view class="picker"> {{ dataInfo.endtime ? dataInfo.endtime : "请选择整改期限" }}</view>
                    </picker> -->
                </view>
                <!-- <view class="cu-form-group ">
                    <view class="title"><text class="cuIcon-favorfill text-xs text-red"></text>整改编号</view>
                    <view>{{ dataInfo.rectificationno }}</view>
                </view> -->
               <view class="cu-form-group ">
                    <view class="title">整改内容</view>
                    <view>{{ dataInfo.rectificationcontent }}</view>
                </view>
                <view class="cu-form-group ">
                    <view class="title">整改措施</view>
                    <view><input disabled placeholder="请输入整改措施" name="input" v-model="dataInfo.rectificationmeasures"  class="input-align"></input></view>
                </view>
				<view class="cu-form-group" style="min-height: 0;"></view>
				
				<view class="cu-bar bg-white">
				    <view class="action">整改图片</view>
				</view>
				<view class="cu-bar bg-white ">
				    <js-uploadfile v-model="dataInfo.dataMap"  uploadType='all' :biz-key="dataInfo.id" biz-type="rectList_file"             
				     :deletable="false"
				     customBtn="false"></js-uploadfile>
				</view>
				
				
                <view class="cu-bar bg-white">
                    <view class="action"><text class="cuIcon-favorfill text-xs text-red"></text>整改结果</view>
                </view>
                <view class="cu-form-group">
                  <textarea
                    maxlength="-1"
                    v-model="dataInfo.rectificationresult"
                    @input="textareaAInput(dataInfo,$event)"
                    placeholder="请输入整改结果"
                  ></textarea>
                </view>
                <view class="cu-form-group">
                    <view class="title"><text class="cuIcon-favorfill text-xs text-red"></text>整改日期</view>
                    <picker mode="date" :value="dataInfo.rectificationdate"  @change="DateChange('rectificationdate',$event)" >
                        <view class="picker"> {{ dataInfo.rectificationdate ? dataInfo.rectificationdate : "请选择整改日期" }}</view>
                    </picker>
                </view>
                <view class="cu-form-group" style="min-height: 0;"></view>

                <view class="cu-bar bg-white">
                    <view class="action"><text class="cuIcon-favorfill text-xs text-red"></text>完成图片</view>
                </view>
                <view class="cu-bar bg-white ">
                    <js-uploadfile v-model="dataInfo.dataMap" :biz-key="dataInfo.id" biz-type="pmRectification_image"             
                     ></js-uploadfile>
                </view>
          </view>
          <view style="height: 200rpx" ></view>
        <view class="btn-group cu-bar foot cu-bar1" >
            <button class="cu-btn bg-blue shadow-blur" @click="save">上传整改结果</button>
            <!-- <button class="cu-btn text-green line-blue shadow">整改验收</button> -->
        </view>
          <!-- v-if="status == vuex_config.zgStatus" -->
        </form>
        
    </view>
</template>
<script>
import xmInfo from "@/pages/zfgs/index/componetns/xmInfo.vue";
import {hasPermission} from '@/common/fire.js'
export default {
  components: { xmInfo },
  data() {
    return {
      startTime: false, //控制日期显示
      switchA: false,
      modalName: null,
      uploadOptions: {},
      modalNameDetail: null,
      showAddDetail: false,
      dataInfo: {},
      showButton: true,
      flag: hasPermission('proj:zg:pmRectification:edit'),
      status: "",
      projectno: "",
      projectname: "",
    };
  },
  onLoad(params) {
    let obj = {};
    if (params.id) {
      obj = params;
    } else {
      let item = JSON.parse(params.item);
      obj = {
        projectno: item.projectno,
        name: item.projectname,
      };
      this.projectno = item.projectno;
      this.projectname = item.projectname;
    }
    this.status = params.status;

    this.$u.api.zfgs.zgForm(obj).then((res) => {
      this.dataInfo = res.pmRectification;
      this.dataInfo.projectno = this.dataInfo.projectno
        ? this.dataInfo.projectno
        : this.projectno;
      this.dataInfo.name = this.dataInfo.name
        ? this.dataInfo.name
        : this.projectname;
    });

  },
  methods: {
    switch1Change(e) {
      if (e.detail.value) {
        this.dataInfo.checkresult = "合格";
      } else {
        this.dataInfo.checkresult = "不合格";
      }
    },
    textareaAInput(item, e) {
      if (item.rectificationresult == undefined) {
        this.$set(item, "checkopinion", e.detail.value);
      } else {
        this.$set(item, "rectificationresult", e.detail.value);
      }
    },

    save() {
      // if (!this.dataInfo.rectificationmeasures) {
      //     this.$u.toast("整改措施必填");
      //     return;
      //   }
      //   if (!this.dataInfo.rectificationcontent) {
      //     this.$u.toast("整改内容必填");
      //     return;
      //   }
        if (!this.dataInfo.rectificationresult) {
          this.$u.toast("整改结果必填");
          return;
        }
        // if (!this.dataInfo.endtime) {
        //   this.$u.toast("整改期限必填");
        //   return;
        // }
        if (!this.dataInfo.rectificationdate) {
          this.$u.toast("整改日期必选");
          return;
        }
        if (
          !this.dataInfo.dataMap ||
          !this.dataInfo.dataMap.pmRectification_image
        ) {
          this.$u.toast("完成图片必传");
          return;
        }
    //   if (this.status != this.vuex_config.zgStatus) {

    //   } else {
    //     if (!this.dataInfo.checkdate) {
    //       this.$u.toast("验收时间必选");
    //       return;
    //     }

    //     if (!this.dataInfo.checkopinion) {
    //       this.$u.toast("验收意见必填");
    //       return;
    //     }
    //     if (!this.dataInfo.checkresult) {
    //       this.dataInfo.checkresult = "不合格";
    //     }
    //   }
      if (this.isSubmitting) {
        return;
      } else {
        this.isSubmitting = true;
        try {
          // 去除this.dataInfo.status 属性
          delete this.dataInfo.status;
          this.$u.api.zfgs.pmRectificationUpdateResult(this.dataInfo).then((res) => {
            if (res.result == "true") {
              this.$u.toast(res.message);
              setTimeout(() => {
                uni.navigateBack({
                  delta: 1,
                });
              }, 500);
            } else {
              uni.showModal({
                title: "提示",
                content: res.message,
                showCancel: false,
                success: (res) => {},
              });
            }
          });
        } catch (error) {
          this.$u.toast(error.message);
        } finally {
          this.isSubmitting = false;
        }
      }
    },
    startConfirm(e) {
      this.dataInfo.endtime = e.year + "-" + e.month + "-" + e.day;
    },
    SwitchA(e) {
      // this.switchA = e.detail.value
    },
    // DateChange(e) {
    //   this.date = e.detail.value;
    // },
    DateChange(item, e) {
      console.log(e.detail.value);
      //   this.dataInfo.inspectiondate = e.detail.value;
      //   更改巡检日期响应式
      if (item === "endtime") {
        this.$set(this.dataInfo, "endtime", e.detail.value);
      } else if (item === "rectificationdate") {
        this.$set(this.dataInfo, "rectificationdate", e.detail.value);
      } else if (item === "checkdate") {
        this.$set(this.dataInfo, "checkdate", e.detail.value);
      }
    },
    // textareaAInput(e) {
    //   this.dataInfo.dmark = e.detail.value;
    // },
    addDetail() {
      this.showAddDetail = true;

      this.modalNameDetail = "bottomModal";

      console.log(this.modalNameDetail);
    },
    modalNameDetailEmit(e) {
      this.modalNameDetail = e;
    },

    ViewImage(imageList, e) {
      uni.previewImage({
        urls: imageList,
        current: e.currentTarget.dataset.url,
      });
    },
    DelImg(e) {
      uni.showModal({
        title: "",
        content: "确定要删除吗？",
        cancelText: "取消",
        confirmText: "确认",
        success: (res) => {
          if (res.confirm) {
            this.$delete(
              this.dataInfo.dImageListst,
              e.currentTarget.dataset.index
            );
          }
        },
      });
    },
    ChooseImage() {
      uni.chooseImage({
        count: 4, //默认9
        sizeType: ["original", "compressed"], //可以指定是原图还是压缩图，默认二者都有
        sourceType: ["album"], //从相册选择
        success: (res) => {
          if (this.dataInfo.finishImgList.length != 0) {
            this.dataInfo.finishImgList = this.dataInfo.finishImgList.concat(
              res.tempFilePaths
            );
          } else {
            this.dataInfo.finishImgList = res.tempFilePaths;
          }

          console.log(this.dataInfo, "this.dataInfo");
          this.$u.toast("上传成功");
        },
      });
    },
  },
};
</script>
<style lang="scss" scoped>
.pre {
  // 空格或者换行符换行
  white-space: pre-wrap;
}
/deep/.u-input__input.data-v-460c1d26 {
  text-align: right !important;
}
.action {
  color: #303133;
}
.title {
  flex-shrink: 0;
}
.text-sl {
  font-size: 22px !important;
}
.cu-bar1 {
  min-height: 80px;
}
.cu-btn {
  font-size: 16px;
  height: 40px;
}
.foot {
  z-index: 997;
  background: #fff;
}
.green {
  color: green;
}
.input-align {
  text-align: right;
}
::v-deep .u-input__input {
  text-align: right;
}
.text-xs {
  font-size: 18rpx !important;
}
.cuIcon-kb::before {
    // content 为空白
    display: inline-block;
    content: ' ';
    width: 18rpx;
    height: 100%;
    
}
</style>